package com.zhuoyue.web.controller.system;

import java.util.List;

import com.zhuoyue.system.domain.vo.JointControlRelationVo;
import com.zhuoyue.system.mapper.SysDeptMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhuoyue.common.annotation.Log;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.enums.BusinessType;
import com.zhuoyue.system.domain.JointControlRelation;
import com.zhuoyue.system.service.IJointControlRelationService;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.common.core.page.TableDataInfo;

/**
 * 多联多控Controller
 *
 * @author zyzn
 * @date 2021-09-24
 */
@RestController
@RequestMapping("/system/relation")
public class JointControlRelationController extends BaseController {
    @Autowired
    private IJointControlRelationService jointControlRelationService;

    /**
     * 查询多联多控列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JointControlRelation jointControlRelation) {
        startPage();
        List<JointControlRelationVo> list = jointControlRelationService.selectJointControlRelationList(jointControlRelation);
        return getDataTable(list);
    }

    /**
     * 导出多联多控列表
     */
    @Log(title = "多联多控", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(JointControlRelation jointControlRelation) {
        List<JointControlRelationVo> list = jointControlRelationService.exportJointControlRelationList(jointControlRelation);
        ExcelUtil<JointControlRelationVo> util = new ExcelUtil<>(JointControlRelationVo.class);
        return util.exportExcel(list, "联控");
    }

    /**
     * 获取多联多控详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(jointControlRelationService.selectJointControlRelationById(id));
    }

    /**
     * 新增多联多控
     */
    @Log(title = "多联多控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JointControlRelation jointControlRelation) {
        return toAjax(jointControlRelationService.insertJointControlRelation(jointControlRelation));
    }

    /**
     * 修改多联多控
     */
    @Log(title = "多联多控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JointControlRelation jointControlRelation) {
        return toAjax(jointControlRelationService.updateJointControlRelation(jointControlRelation));
    }

    /**
     * 删除多联多控
     */
    @Log(title = "多联多控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(jointControlRelationService.deleteJointControlRelationByIds(ids));
    }
}
